﻿/* ============================================================================
(c) Copyright 2012 Hewlett-Packard Development Company, L.P.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge,publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
============================================================================ */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace HPCloud.Objects.Domain.BlockStorage
{
    // Type created for JSON at <<root>> --> attachments
    [System.Runtime.Serialization.DataContractAttribute(Name = "attachments")]
    public partial class Attachments
    {

    }

    // Type created for JSON at <<root>>
    [System.Runtime.Serialization.DataContractAttribute()]
    public partial class RootVolumeClass
    {
        [System.Runtime.Serialization.DataMemberAttribute()]
        public Volume[] volumes;
    }

    // Type created for JSON at <<root>>
    [System.Runtime.Serialization.DataContractAttribute(Name = "volume")]
    public partial class SingleVolumeClass : BaseEntity
    {
        [System.Runtime.Serialization.DataMemberAttribute()]
        public Volume volume; 
    }      


    [System.Runtime.Serialization.DataContractAttribute(Name = "volumes")]
    public class Volume : BaseEntity
    {
        private string   _status;
        private string   _description;
        private string   _availabilityZone;
        private VolumeAttachment[] _attachments;
        private string   _volumeType;
        private string   _size;
        private DateTime _creationDate;
        private string _id;
        private string _device;
        public Dictionary<string, string> _metadata = new Dictionary<string, string>();
        private string _attachedTo = null;
        private bool _isBootable = false;
        private string _name;
       
             
        #region Properties
        //=========================================================================================
        /// <summary>
        /// 
        /// </summary>
        //=========================================================================================  
        [DataMember(Name = "displayName")]
        public new string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        //=========================================================================================
        /// <summary>
        /// 
        /// </summary>
        //=========================================================================================  
        public bool IsBootable
        {
            get { return _isBootable; }
            set { _isBootable = value; }
        }
        //=========================================================================================
        /// <summary>
        /// 
        /// </summary>
        //=========================================================================================  
        public string Device
        {
            get
            {
                if ((this.Attachments != null && this.Attachments.Count() == 1)) 
                {
                    return this.Attachments[0].Device;
                }
                else
                {
                    return _device;
                }
           
            }
            set
            {
                _device = value;
            }
        }
        //=========================================================================================
        /// <summary>
        /// 
        /// </summary>
        //=========================================================================================  
        public string AttachedTo
        {
            get
            {
                if (_attachedTo != null)
                    return _attachedTo;
                else
                {
                    if (this.Attachments.Count() == 1)
                    {
                        return this.Attachments[0].ServerId;
                    }
                    else
                    {
                        return "Not Attached";
                    }
                }      
            }
            set
            {
                _attachedTo = value;
            }
        }
        //=========================================================================================
        /// <summary>
        /// 
        /// </summary>
        //=========================================================================================  
        [System.Runtime.Serialization.DataMemberAttribute(Name = "metadata")]
        public Dictionary<string, string> Metadata
        {
            get { return _metadata; }
            set { _metadata = value; }
        }
        //=========================================================================================
        /// <summary>
        /// 
        /// </summary>
        //=========================================================================================  
        [DataMember(Name = "createdAt")]
        public DateTime CreationDate
        {
            get { return _creationDate; }
            set { _creationDate = value; }
        }
        //=========================================================================================
        /// <summary>
        /// 
        /// </summary>
        //=========================================================================================    
        [DataMember(Name = "size")]
        public string Size
        {
            get { return _size; }
            set { _size = value; }
        }
        //=========================================================================================
        /// <summary>
        /// 
        /// </summary>
        //=========================================================================================  
        [DataMember(Name = "volumeType")]
        public string VolumeType
        {
            get { return _volumeType; }
            set { _volumeType = value; }
        }
        //=========================================================================================
        /// <summary>
        /// 
        /// </summary>
        //=========================================================================================  
        [DataMember(Name = "attachments")]
        public VolumeAttachment[] Attachments
        {
            get { return _attachments; }
            set { _attachments = value; }
        }
        //=========================================================================================
        /// <summary>
        /// 
        /// </summary>
        //=========================================================================================  
        [DataMember(Name = "availabilityZone")]
        public string AvailabilityZone
        {
            get { return _availabilityZone; }
            set { _availabilityZone = value; }
        }
        //=========================================================================================
        /// <summary>
        /// 
        /// </summary>
        //=========================================================================================  
        [DataMember(Name = "displayDescription")]
        public string Description
        {
            get { return _description; }
            set { _description = value; }
        }
        //=========================================================================================
        /// <summary>
        /// 
        /// </summary>
        //=========================================================================================  
        [DataMember(Name = "status")]
        public string Status
        {
            get { return _status; }
            set { _status = value; }
        }
        #endregion
    }
}
